{include file="public/layout" /}
<body class="eyou_body_xin">
<div id="toolTipLayer" style="position: absolute; z-index: 9999; display: none; visibility: visible; left: 95px; top: 573px;"></div>
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
{include file="store/left" /}
<div id="geduan_div" class="h15"></div>
<div class="page" style="min-width:auto;margin-left:115px;padding-bottom: 15px;">
    <!-- <div class="fixed-bar">
        <div class="item-title mb0">
            <a class="back_xin" href="javascript:history.back();"  title="返回"><i class="iconfont e-fanhui"></i></a>
            <div class="subject">
                <h3>微信公众号</h3>
                <h5></h5>
            </div>
        </div>
    </div> -->
    <!-- 操作说明 -->
    <div id="explanation" class="explanation" style="color: rgb(44, 188, 163); background-color: rgb(237, 251, 248); width: 99%; height: 100%;margin-bottom: 15px;">
        <div id="checkZoom" class="title"><i class="fa fa-lightbulb-o"></i>
            <h4 title="提示相关设置操作时应注意的要点">提示</h4>
            <span title="收起提示" id="explanationZoom" style="display: block;"></span>
        </div>
        <ul>
            <li>1，微信公众号：登录 <a href="https://mp.weixin.qq.com" target="_blank">微信公众号平台</a>，在“设置与开发->基本配置”里获取AppID、AppSecret的值，设置IP白名单等。配置可通用于消息通知等。<span style="color: red;">(注：必须是已认证的服务号）</span></li>
            <!-- <li>2，微站点：微信号、二维码是在微站点开启 <span style="color: red;">强制微信模式</span> 时在电脑和移动端展示</li> -->
        </ul>
    </div>
    <div class="flexigrid ncap-form-default htitx">
        <form class="form-horizontal mt15" id="wechat_post_form" action="{:url('Store/wechat_conf')}" method="post">
            
            <div class="hDiv">
                <div class="hDivBox">
                    <table cellspacing="0" cellpadding="0" style="width: 100%">
                        <thead>
                            <tr>
                                <th class="sign w10" axis="col0">
                                    <div class="tc"></div>
                                </th>
                                <th abbr="article_title" axis="col3" class="w10">
                                    <div class="tc">公众号配置</div>
                                </th>
                                <th abbr="ac_id" axis="col4">
                                    <div class=""></div>
                                </th>
                            </tr>
                        </thead>
                    </table>
                </div>
            </div>
            <div style="position: sticky;">
                {notempty name='$ipTips'}
                <dl class="row">
                    <dt class="tit">
                        <label for="url" style="color: red;">注意事项</label>
                    </dt>
                    <dd class="opt">
                        {$ipTips}
                        <span class="err"></span>
                        <p class=""></p>
                    </dd>
                </dl>
                {/notempty}
                {notempty name='$data.apiurl'}
                <!-- <dl class="row">
                    <dt class="tit">
                        <label for="url">服务器地址(URL)</label>
                    </dt>
                    <dd class="opt">
                        {$data.apiurl}
                        <a href="javascript:void(0);" onclick="showtext('apiurl');" class="ncap-btn ncap-btn-green apiurl" data-clipboard-text="{$data.apiurl}">复制URL</a>
                        <span class="err"></span>
                        <p class="">请登录微信公众平台-【开发】-【基本配置】 - 写入服务器地址(URL)</p>
                    </dd>
                </dl> -->
                {/notempty}
                <dl class="row">
                    <dt class="tit">
                        <label for="appid"><em id="em_appid" {empty name='$data.appid'}style="display: none;"{/empty}>*</em>AppID</label>
                    </dt>
                    <dd class="opt">
                        <input type="text" name="appid" id="appid" value="{$data.appid|default=''}" class="input-txt w250" autocomplete="off">
                        <p class="notic-pic"><img src="__SKIN__/images/wechat_appid.png" width="650"></p>
                    </dd>
                </dl>
                <dl class="row">
                    <dt class="tit">
                        <label for="appsecret"><em id="em_appsecret" {empty name='$data.appsecret'}style="display: none;"{/empty}>*</em>AppSecret</label>
                    </dt>
                    <dd class="opt">
                        <input type="text" name="appsecret" id="appsecret" value="{$data.appsecret|default=''}" class="input-txt w250" autocomplete="off">
                        <p class="notic-pic"><img src="__SKIN__/images/wechat_appsecret.png" width="650"></p>
                    </dd>
                </dl>
                <dl class="row none">
                    <dt class="tit">
                        <label for="url"><em id="em_token">*</em>令牌(Token)</label>
                    </dt>
                    <dd class="opt">
                        <input type="text" name="token" placeholder="" value="{$data.token}" id="token" class="input-txt">
                        <span class="err"></span>
                        <p class="notic">公众号平台的Token要与这里的Token保持一致，请登录微信公众平台-【开发】-【基本配置】查看</p>
                    </dd>
                </dl>
                <dl class="row" {empty name='$data.appid'}style="display: none;"{/empty}>
                    <dt class="tit">
                        <label for="title">认证情况</label>
                    </dt>
                    <dd class="opt"> 
                        {if condition="isset($data['type']) && $data['type'] == 2"}
                            <font color="green">已认证</font>（必须是服务号）
                        {else /}
                            <font color="red">未认证</font>（必须是已认证的服务号）
                        {/if}
                        <input type="hidden" name="type" value="{$data.type|default=1}">
                        <span class="err"></span>
                        <p class="notic"></p>
                    </dd>
                </dl>
            </div>
            
            <div class="" style="position: absolute;top: 65px;left: 750px; z-index: 99999;">
                <dl class="row {empty name='$wechat_qrcodeurl'}none{/empty}" id="dl_wechat_qrcode" style="background: #fff;">
                    <dd class="opt">
                        <span id="wechat_span_qrcode"></span>
                        <div class="ercodepic" style="margin-left: 23px;">
                            <img id="wechat_img_qrcode" src="__STATIC__/common/images/loading.gif" width="23" height="23" />
                        </div>
                        <p class="notic"></p>
                    </dd>
                    <dt class="tit" style="text-align: center;line-height: 32px;font-size: 15px;">
                        <label for="baidu_qrcode">扫码订阅消息推送</label>
                    </dt>
                </dl>
            </div>
        </form>
    </div>
    <script type="text/javascript">

        $(function(){
            $('#appid, #appsecret').keyup(function(){
                var appid = $.trim($('#appid').val());
                var appsecret = $.trim($('#appsecret').val());
                if (appid != '' || appsecret != '') {
                    $('#em_appid').show();
                    $('#em_appsecret').show();
                } else {
                    $('#em_appid').hide();
                    $('#em_appsecret').hide();
                }
            });

            function ajax_get_wechat_qrcode()
            {
                var appid = $.trim($('#appid').val());
                var appsecret = $.trim($('#appsecret').val());
                if (appid != '' && appsecret != '') {
                    $('#dl_wechat_qrcode').show();

                    var wechat_qrcodeurl = "{$wechat_qrcodeurl}";
                    if (wechat_qrcodeurl != '') {
                        $('#wechat_img_qrcode').attr('src', wechat_qrcodeurl);
                        setTimeout(function(){
                            $('#wechat_img_qrcode').attr('width', 122).attr('height', 122);
                        },100);
                    }
                }

                $.ajax({
                    url: "{:url('Store/ajax_get_wechat_qrcode', ['_ajax'=>1])}",
                    type: 'GET',
                    dataType: 'JSON',
                    data: {},
                    success: function (res) {
                        if (1 == res.code) {
                            $('#wechat_span_qrcode').hide();
                            $('#wechat_img_qrcode').attr('src', '');
                            $('#wechat_img_qrcode').attr('src', res.data.qrcodeurl).attr('width', 122).attr('height', 122).show();
                        } else {
                            $('#wechat_span_qrcode').html(res.msg);
                            $('#wechat_img_qrcode').hide();
                            return false;
                        }
                    },
                    error: function (e) {
                        $('#wechat_span_qrcode').html(e.responseText);
                        $('#wechat_img_qrcode').hide();
                        return false;
                    }
                });
            }
            ajax_get_wechat_qrcode();
        });

    </script>

    <script type="text/javascript" src="__SKIN__/js/clipboard.min.js"></script>
    <script type="text/javascript">
        function showtext(classname){
            var clipboard1 = new Clipboard("."+classname);clipboard1.on("success", function(e) {layer.msg("复制成功");});clipboard1.on("error", function(e) {layer.msg("复制失败！请手动复制", {icon:2});}); 
        }
    </script>

    {empty name="$global['web_status']"}
    <div class="flexigrid htitx">
        <form class="form-horizontal" id="postMicrosite" method="post">
            <div class="hDiv">
                <div class="hDivBox">
                    <table cellspacing="0" cellpadding="0" style="width: 100%">
                        <thead>
                            <tr>
                                <th class="sign w10" axis="col0">
                                    <div class="tc"></div>
                                </th>
                                <th abbr="article_title" axis="col3" class="w10">
                                    <div class="tc">微站点</div>
                                </th>
                                <th abbr="ac_id" axis="col4">
                                    <div class=""></div>
                                </th>
                            </tr>
                        </thead>
                    </table>
                </div>
            </div>
            
            <div class="ncap-form-default" style="position: sticky;">
                <dl class="row">
                    <dt class="tit"> <label>商城状态</label> </dt>
                    <dd class="opt">
                        <label class="curpoin"><input id="web_status_m0" name="web[web_status_m]" value="0" type="radio" {if condition="!isset($global.web_status_m) OR empty($global.web_status_m)"} checked="checked"{/if}>开启</label>
                        &nbsp;
                        <label class="curpoin"><input id="web_status_m1" name="web[web_status_m]" value="1" type="radio" {if condition="isset($global.web_status_m) AND $global.web_status_m eq 1"} checked="checked"{/if}>关闭</label>
                        <input type="hidden" id="old_web_status_m" value="{$global.web_status_m|default='0'}">
                        <p class="notic">关闭后，商城将无法访问</p>
                    </dd>
                </dl>
                <div id="div_web_status_close_m" class="{if condition='!isset($global.web_status_m) OR empty($global.web_status_m)'}none{/if}">
                    <dl class="row">
                        <dt class="tit"> <label for="web_status_mode_m">&nbsp;</label> </dt>
                        <dd class="opt">
                            <label class="curpoin">
                                <input type="radio" name="web[web_status_mode_m]" value="0" {if condition='empty($global.web_status_mode_m)'}checked="checked"{/if}/>文案显示&nbsp;&nbsp;
                            </label>
                            <label class="curpoin">
                                <input type="radio" name="web[web_status_mode_m]" value="1" {if condition='!empty($global.web_status_mode_m) && 1 == $global.web_status_mode_m'}checked="checked"{/if}/>跳转链接&nbsp;&nbsp;
                            </label>
                            
                        </dd>
                    </dl>
                    <dl class="row dl_web_status_mode_m {if condition='!empty($global.web_status_mode_m)'}none{/if}" id="dl_web_status_mode_m_0">
                        <dt class="tit"> <label for="web_status_text_m">&nbsp;</label> </dt>
                        <dd class="opt">
                            <input id="web_status_text_m" name="web[web_status_text_m]" value="{if condition='!isset($global.web_status_text_m)'}网站暂时关闭，维护中……{else /}{$global.web_status_text_m}{/if}" class="input-txt" type="text" autocomplete="off" />
                            <p class="notic"></p>
                        </dd>
                    </dl>
                    <dl class="row dl_web_status_mode_m {if condition='empty($global.web_status_mode_m) || 1 != $global.web_status_mode_m'}none{/if}" id="dl_web_status_mode_m_1">
                        <dt class="tit"> <label for="web_status_url_m">&nbsp;</label> </dt>
                        <dd class="opt">
                            <input id="web_status_url_m" name="web[web_status_url_m]" value="{$global.web_status_url_m|default=''}" class="input-txt" type="text" placeholder="关闭后，访问网站跳转的URL，http://" autocomplete="off"/>
                            <p class="notic">如果设置跳转URL，必须带有http:// 或 https://</p>
                        </dd>
                    </dl>
                    
                </div>
                <dl class="row">
                    <dt class="tit">
                        <label for="wechat_name">展示微信号</label>
                    </dt>
                    <dd class="opt">
                        <input type="text" name="login[wechat_name]" id="wechat_name" value="{$login.wechat_name|default=''}" class="input-txt">
                        <p class="notic"></p>
                    </dd>
                </dl>

                <dl class="row">
                    <dt class="tit">
                        <label for="wechat_pic">展示二维码</label>
                    </dt>
                    <dd class="opt">
                        <div class="input-file-show">
                            <span class="show">
                                <a id="img_a_wechat_pic" class="nyroModal" rel="gal" href="{$login.wechat_pic|default='javascript:void(0);'}?t={php}echo time();{/php}" target="_blank">
                                    <i id="img_i_wechat_pic" class="fa fa-picture-o" {notempty name="$login.wechat_pic"}onmouseover="layer_tips=layer.tips('<img src={$login.wechat_pic|default=''}?t={php}echo time();{/php} width=300 height=300>',this,{tips: [1, '#fff']});"{/notempty} onmouseout="layer.close(layer_tips);"></i>
                                </a>
                            </span>
                            <span class="type-file-box">
                                <input type="text" id="wechat_pic" name="login[wechat_pic]" value="{$login.wechat_pic|default=''}" class="type-file-text" autocomplete="off">
                                <input type="button" name="button" id="button1" value="选择上传..." class="type-file-button">
                                <input class="type-file-file" onclick="GetUploadify(1, '', 'allimg', 'wechat_pic_call_back')" size="30" hidefocus="true" nc_type="change_site_logo" title="点击前方预览图可查看大图，点击按钮选择文件并提交表单后上传生效">
                            </span>
                        </div>
                        <span class="err"></span>
                        <p class="notic-pic"><img src="__STATIC__/admin/images/wzd-shili.jpg" width="278" height="195" /></p>
                    </dd>
                </dl>
                <input type="hidden" id="WX_appid" value="{$login.appid|default=''}">
            </div>

        </form>
    </div>
    <div class="flexigrid htitx">
        <form class="form-horizontal" id="postMicrosite" method="post">
            <div class="hDiv">
                <div class="hDivBox">
                    <table cellspacing="0" cellpadding="0" style="width: 100%">
                        <thead>
                            <tr>
                                <th class="sign w10" axis="col0">
                                    <div class="tc"></div>
                                </th>
                                <th abbr="article_title" axis="col3" class="w10">
                                    <div class="tc">分享设置</div>
                                </th>
                                <th abbr="ac_id" axis="col4">
                                    <div class=""></div>
                                </th>
                            </tr>
                        </thead>
                    </table>
                </div>
            </div>
            <div class="share-con">
                <div class="share-col-4">
                    <div class="share-content">
                        <div class="share-head">
                            <p class="title-l">商城首页</p>
                            <a class="title-r" href="javascript:void(0);" data-href="{:url('Store/wechat_conf_share')}" onclick="openFullframe(this, '首页分享设置', '640px', '500px');">编辑</a>
                        </div>
                        <div class="share-bot">
                            <p class="share-title" name="title">
                                <span title="{ey_webname}">{ey_webname}</span>
                            </p>
                            <div class="share-box">
                                <div class="share-font">
                                    <span class="span-show">用心精选<br>常来逛逛</span>
                                </div>
                                <div class="share-img" style="background-image:url('')">
                                    <span>分享图标</span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="share-col-4">
                    <div class="share-content">
                        <div class="share-head">
                            <p class="title-l">商品列表页</p>
                            <a class="title-r" href="javascript:void(0);" data-href="{:url('Store/wechat_conf_share')}" onclick="openFullframe(this, '列表页分享设置', '640px', '500px');">编辑</a>
                        </div>
                        <div class="share-bot">
                            <p class="share-title" name="title">
                                <span>未设置分享标题</span>
                            </p>
                            <div class="share-box">
                                <div class="share-font">
                                    <span class="span-show">用心精选<br>常来逛逛</span>
                                </div>
                                <div class="share-img" style="background-image:url('')">
                                    <span>分享图标</span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="share-col-4">
                    <div class="share-content">
                        <div class="share-head">
                            <p class="title-l">商品详情页</p>
                            <a class="title-r" href="javascript:void(0);" data-href="{:url('Store/wechat_conf_share')}" onclick="openFullframe(this, '详情页分享设置', '640px', '500px');">编辑</a>
                        </div>
                        <div class="share-bot">
                            <p class="share-title" name="title">
                                <span title="{ey_webname}">{ey_webname}</span>
                            </p>
                            <div class="share-box">
                                <div class="share-font">
                                    <span class="span-show">用心精选<br>常来逛逛</span>
                                </div>
                                <div class="share-img" style="background-image:url('')">
                                    <span>商品主图</span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
    {/empty}

    <div class="flexigrid htitx">
        <div class="ncap-form-default" style="position: sticky;">
            <div class="bot">
                <a href="JavaScript:void(0);" onclick="checkForm();" class="ncap-btn-big ncap-btn-green" id="submitBtn">确认提交</a>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        $(function(){
            //操作提示缩放动画
            $("#microsite_checkZoom").toggle(
                function() {
                    $("#microsite_explanation").animate({
                        color: "#FFF",
                        backgroundColor: "#4FD6BE",
                        width: "80",
                        height: "20",
                    },300);
                    $("#microsite_explanationZoom").hide();
                },
                function() {
                    $("#microsite_explanation").animate({
                        color: "#2CBCA3",
                        backgroundColor: "#EDFBF8",
                        width: "99%",
                        height: "20",
                    },300,function() {
                        $(this).css('height', '100%');
                    });
                    $("#microsite_explanationZoom").show();
                }
            );
        })
        // 提交
        function submit_microsite(){
            layer_loading("正在处理");
            $.ajax({
                url: "{:url('System/microsite', ['_ajax'=>1])}",
                type: 'POST',
                dataType: 'JSON',
                data: $('#postMicrosite').serialize(),
                success: function(res){
                    layer.closeAll();
                    if (1 == res.code) {
                        layer.msg(res.msg, {shade: 0.1, time: 1000}, function(){
                            window.location.reload();
                        });
                    } else {
                        var icon = 2;
                        try{
                            if (res.data.icon) {
                                icon = res.data.icon;
                            }
                        }catch(e){}
                        showErrorAlert(res.msg, icon);
                        return false;
                    }
                },
                error: function(e){
                    layer.closeAll();
                    showErrorMsg(e.responseText);
                    return false;
                }
            });
        }
    
        // 检测是否配置微信参数
        function DetectConfig(type) {
            if (3 == type) {
                $('#shop_micro0').removeAttr("disabled");
                return false;
            }
    
            var WX_appid = $('#WX_appid');
            if (!WX_appid.val() || '' == WX_appid.val()) {
                if (1 == type) {
                    $("#shop_micro0").click();
                } else if (2 == type) {
                    $("#shop_force_use_wechat0").click();
                }
                showErrorAlert('请先完善微信公众号配置');
                return false;
            }
    
            if (2 == type) {
                // 设置微信端开启
                $("#shop_force_use_wechat1, #shop_micro1").attr('checked', true);
                $('#shop_micro0').attr("disabled", "disabled");
            }
        }
    
        // 加载图片显示
        function wechat_pic_call_back(fileurl_tmp) {
            $("#wechat_pic").val(fileurl_tmp);
            $("#img_a_wechat_pic").attr('href', fileurl_tmp);
            $("#img_i_wechat_pic").attr('onmouseover', "layer_tips=layer.tips('<img src="+fileurl_tmp+" width=300 height=300>',this,{tips: [1, '#fff']});");
        }

        // 判断输入框是否为空
        function checkForm(){
            var appid = $.trim($('#appid').val());
            var appsecret = $.trim($('#appsecret').val());
            if (appid != '' || appsecret != '') {
                if(appid == ''){
                    showErrorMsg('AppID不能为空！');
                    $('input[name=appid]').focus();
                    return false;
                }
                if(appsecret == ''){
                    showErrorMsg('AppSecret不能为空！');
                    $('input[name=appsecret]').focus();
                    return false;
                }
            }
            layer_loading('正在处理');
            $.ajax({
                url: "{:url('Store/wechat_conf', ['_ajax'=>1])}",
                type: 'POST',
                dataType: 'JSON',
                data: $('#wechat_post_form').serialize(),
                success: function (res) {
                    layer.closeAll();
                    if (1 == res.code) {
                        layer.msg(res.msg, {shade: layer_shade, time: 1000}, function(){
                            window.location.reload();
                        });
                    } else {
                        showErrorAlert(res.msg);
                        return false;
                    }
                },
                error: function (e) {
                    layer.closeAll();
                    showErrorAlert(e.responseText);
                    return false;
                }
            });
        }
    </script>
{include file="public/footer" /}